package cj.web.marriage.dao;
/*
 *  
 *  
*/
import java.util.List;
import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.marriage.domain.Vote;

/**
 * 
 * @author 
 *
 */
@DAO
public interface VoteDAO{
	
	@SQL("SELECT * FROM Vote WHERE deleteFlag=1 ORDER BY orderNo ")
    List<Vote> queryAll();
	
	@SQL("SELECT * FROM Vote WHERE deleteFlag=1 #if(:t.name!=''){ AND name LIKE '%##(:t.name)%' } ORDER BY updateAt DESC LIMIT :t.start,:t.length ")
    List<Vote> query(@SQLParam("t") Vote vote);
		
	@SQL("SELECT count(1) FROM Vote WHERE deleteFlag=1 #if(:t.name!=''){ AND name LIKE '%##(:t.name)%' } " )
    int querySize(@SQLParam("t") Vote vote);
    
    @SQL("select * from Vote where id=:1")
    Vote queryById(int id);
    
    @SQL("INSERT INTO Vote ("
			        		+ "img,"
			        		+ "name,"
			        		+ "descs,"
			        		+ "orderNo,"
			        		+ "startDate,"
			        		+ "endDate,"
			        		+ "deleteFlag,"
			        		+ "createUser,"
			        		+ "createAt,"
			        		+ "updateUser,"
			        		+ "updateAt"
							+") VALUES ("
							+ ":t.img,"
							+ ":t.name,"
							+ ":t.descs,"
							+ ":t.orderNo,"
							+ ":t.startDate,"
							+ ":t.endDate,"
							+ "1,"
							+ ":t.createUser,"
							+ "now(),"
							+ ":t.updateUser,"
							+ "now()"
					+")")
    void create(@SQLParam("t") Vote vote);
	
	@SQL("UPDATE Vote SET "
	    			        + "img=:t.img,"
	    			        + "name=:t.name,"
	    			        + "descs=:t.descs,"
	    			        + "orderNo=:t.orderNo,"
	    			        + "startDate=:t.startDate,"
	    			        + "endDate=:t.endDate,"
	    			        + "updateUser=:t.updateUser,"
	    			        + "updateAt=now()"
    						+ " WHERE id=:t.id")
    void update(@SQLParam("t") Vote vote);
    
    @SQL("UPDATE Vote SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);
}